package com.guijq.graphqldemo.resolver;

import java.util.List;

import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.guijq.graphqldemo.dao.AuthorRepository;
import com.guijq.graphqldemo.dao.BookRepository;
import com.guijq.graphqldemo.dao.entity.Author;
import com.guijq.graphqldemo.dao.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yangjf
 * @version 0.1.0
 * @time 2018/9/19/019
 */
@Component
public class Query implements GraphQLQueryResolver {

    @Autowired
    private BookRepository bookRepository;

    @Autowired
    private AuthorRepository authorRepository;

    public List<Book> books() {
        return bookRepository.findAll();
    }

    public Book book(Long id){
        return bookRepository.findById(id).get();
    }

    public List<Author> authors() {
        return authorRepository.findAll();
    }
}